package net.hailxenu.stats;

import java.sql.*;

public class SqlHandler {

    Connection connection;
    
    public SqlHandler(String Host, String User, String Pass, String DBName) throws SQLException
    {
        new com.mysql.jdbc.Driver();
        connection = (Connection) DriverManager.getConnection("jdbc:mysql://" + Host + ":3306/" + DBName, User, Pass); // TODO: Config
    }

    public boolean write(String query)
    {
        Boolean result = false;
        try
        {
            Statement st = connection.createStatement();
            result = st.execute(query);
        } catch (Exception ex)
        {
            ex.printStackTrace();
        }
        return result.booleanValue();
    }

    public ResultSet read(String query)
    {
        ResultSet result;
        try
        {
            Statement st = connection.createStatement();
            result = st.executeQuery(query);
        } catch (Exception ex)
        {
            result = null;
        }
        return result;
    }
}
